#include "ThreadPool.hpp"
#include <stdlib.h>
#include <unistd.h>

void task1()
{
    char name[80];
    pthread_getname_np(pthread_self(), name, 80);
    LOG(LogLevel::INFO) << name << " 处理数据库任务";
}

void task2()
{
    char name[80];
    pthread_getname_np(pthread_self(), name, 80);
    LOG(LogLevel::INFO) << name << " 处理网络任务";

}

void task3()
{
    char name[80];
    pthread_getname_np(pthread_self(), name, 80);
    LOG(LogLevel::INFO) << name << " 处理系统任务";

}

void task4()
{
    char name[80];
    pthread_getname_np(pthread_self(), name, 80);
    LOG(LogLevel::INFO) << name << " 处理web任务";

}

int main()
{

    ThreadPool* p= ThreadPool::GetInstance();
    ThreadPool& tp= *p;
    tp.Start();
    int cnt = 20;

    task_t a[5];
    a[0] = task1, a[1] = task2, a[2] = task3, a[3] = task4;

    srand(time(nullptr));

    while (cnt--)
    {
        int t = rand() % 4;
        tp.Enqueue(a[t]);
        sleep(1);
    }

    tp.Stop();
    tp.Join();

    return 0;
}